﻿@model  RBAC.Web.Models.PermissionModel
@using RBAC.Web.CustomHelpers
@using RBAC.Web.Mapper
@using RBAC.Web.Utilities
@{
    ViewBag.Title = "Edit Permission";

    string returnUrl = "";

    string RoleCode = "";
    if (TempData["RoleLookupField"] == null || String.IsNullOrEmpty(TempData["RoleLookupField"].ToString()))
    {
        returnUrl = Url.Action("ListPermission", "Permission");
    }
    else
    {
        RoleCode = TempData["RoleLookupField"].ToString();
        returnUrl = Url.Action("EditRole", "Role", new { RoleCode = RoleCode });
    }  
																																												 
}
@section Styles {
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/form.js?3")" type="text/javascript"></script>
    <link href="@Url.Content("~/Content/themes/base/jquery.ui.all.css")" rel="stylesheet" />
    <link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/themes/base/jquery.ui.datepicker.css")" rel="stylesheet" type="text/css" />

    <link href="@Url.Content("~/Content/bootstrap/css/utility.css")" rel="stylesheet"		type="text/css">

    <script type="text/javascript">
        $(function () {
            //How to setup Datepicker
            SetDatePicker("CreateDate", new Date(), '-71Y', 'c-70:c');
            SetDatePicker("FreeDate");
            
            //How to setup Lookup
            SetExternalLookupFor("Permission_Role", "Permission_RoleGetExternalLookup", 
"Permission_RolePopExternalLookup", 'Permission_Role|Permission_RoleLookupField');
			
            SetExternalLookupFor("Permission_Function", "Permission_FunctionGetExternalLookup", 
"Permission_FunctionPopExternalLookup", 'Permission_Function|Permission_FunctionLookupField');
			
            SetExternalLookupFor("Permission_RoleLookup", "Permission_RoleLookupGetExternalLookup", 
"Permission_RoleLookupPopExternalLookup", 'Permission_RoleLookup|Permission_RoleLookupLookupField|RoleLookupId');
			
			
            //Master Detail
			 
							 
							 
							 
							 
							 
							 
							 
        });
    </script>
}


<div class="row">
    <div class="col-lg-12">
        <h2 class="page-header">Permission</h2>
    </div>
</div>

@using (Html.BeginForm("Update", "Permission", FormMethod.Post, new { @id = "form-Permission", @class = "form-horizontal", role = "form" }))
{


    //version 1.4 Bootstrap 7/4/2557
    <div class="panel panel-primary">
        <div class="panel-heading">PermissionModel</div>
        <div class="panel-body">


            @Html.Hidden("Parent_RoleRoleCode", @RoleCode)



            @Html.HiddenFor(model => model.Id)

            <div class="form-group row">



                <div class="col-md-6">
                    <div class="col-md-4">
                        <label class="word-control-res">@Html.LabelFor(model => model.PermissionName)</label>
                    </div>
                    <div class="col-md-8">
                        @Html.TextBoxFor(model => model.PermissionName, new { @class = "form-control" })

                    </div>
                    <div class="col-md-offset-4 col-md-8">
                        @Html.ValidationMessageFor(model => model.PermissionName)
                    </div>
                </div>
                @Html.HiddenFor(model => model.Id)
                <input type="hidden" name="Mode" value="Edit" />
                <input type="hidden" name="OldValue" value="@(Model.PermissionName == null ? "" : Model.PermissionName)" />



                <div class="col-md-6">
                    <div class="col-md-4">
                        <label class="word-control-res">@Html.LabelFor(model => model.Description)</label>
                    </div>
                    <div class="col-md-8">
                        @Html.TextBoxFor(model => model.Description, new { @class = "form-control" })

                    </div>
                    <div class="col-md-offset-4 col-md-8">
                        @Html.ValidationMessageFor(model => model.Description)
                    </div>
                </div>

            @* chayawooth******************@

            <div class="col-md-6">
                <div class="col-md-4">
                    <label class="word-control-res">@Html.LabelFor(model => model.Role)</label>
                </div>
                <div class="col-md-8">
                    @Html.ExternalLookup(model => model.RoleRoleCode, "Permission_Role").For(model => model.Role).Render(Utilities.CheckNullOrEmpty<string>(RoleCode))
                </div>
                <div class="col-md-offset-4 col-md-8">
                    @Html.ValidationMessageFor(model => model.RoleRoleCode)
                </div>
            </div>


            <div class="col-md-6">
                <div class="col-md-4">
                    <label class="word-control-res">@Html.LabelFor(model => model.Function)</label>
                </div>
                <div class="col-md-8">
                    @Html.ExternalLookup(model => model.FunctionFuncName, "Permission_Function").For(model => model.Function).Render()
                </div>
                <div class="col-md-offset-4 col-md-8">
                    @Html.ValidationMessageFor(model => model.FunctionFuncName)
                </div>
            </div>
            @* *****************************@



                <div class="col-md-6">
                    <div class="col-md-4">
                        <label class="word-control-res">@Html.LabelFor(model => model.CreateDate)</label>
                    </div>
                    <div class="col-md-8 ">
                        @Html.DatePickerFor(model => model.CreateDate, "CreateDate", true)

                    </div>
                    <div class="col-md-offset-4 col-md-8">
                        @Html.ValidationMessageFor(model => model.CreateDate)
                    </div>
                </div>





                <div class="col-md-6">
                    <div class="col-md-4">
                        <label class="word-control-res">@Html.LabelFor(model => model.PermissionStatus)</label>
                    </div>
                    <div class="col-md-8">
                        @Html.RadioButtonForSelectList(model => model.PermissionStatus, PermissionStatusMapper.GetPermissionStatusSelectList())
                    </div>
                    <div class="col-md-offset-4 col-md-8">
                        @Html.ValidationMessageFor(model => model.PermissionStatus)
                    </div>
                </div>
            </div>

   


            <div class="col-md-6">
                <div class="btn-group">
                    <label>
                        <input type="button" name="btnBack" value="Cancel" class="btn btn-primary" id="button-back" onclick="location.href='@returnUrl    '"/>
                    </label>
                    <label>
                        <input type="Button" value="Save" id="button-save" class="btn btn-primary" onclick="JavaScript: SaveButtonClick()" />
                    </label>
                    <label>
                        <input type="button" name="btnDelete" value="Delete" class="btn btn-primary" id="button-delete" onclick="JavaScript: DeleteButtonClick()" />
                    </label>
                </div>
            </div>




        </div>
    </div> 

    // Master Detail Dest Class
}




<div class="modal" id="Delete">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">Delete Permission</h4>
            </div>
            <div class="modal-body">
                Do you want to delete?
            </div>
            <div class="modal-footer">
                <button type="button" data-dismiss="modal" id="confirm-delete" class="btn btn-primary">YES</button>
                <button type="button" data-dismiss="modal" class="btn btn-primary">NO</button>
            </div>
        </div>
    </div>
</div>


<div class="modal" id="Save">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">Save Permission</h4>
            </div>
            <div class="modal-body">
                Do you want to save?
            </div>
            <div class="modal-footer">
                <button type="button" data-dismiss="modal" id="confirm-save" class="btn btn-primary">YES</button>
                <button type="button" data-dismiss="modal" class="btn btn-primary">NO</button>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function () {

        $("#button-delete").click(function () {
              
          
            $('#Delete').modal('show');
            $('#confirm-delete').click(function () {
                $.post('@Url.Action("DeletePermissionById", "Permission")',$("#form-Permission").serialize(),function (data) {
                    var s = '@returnUrl'
                    if(s.indexOf("?") !== -1)
                        window.location.href = s + '&result=' + data + '&operation=delete';   
                    else
                        window.location.href = s + '?result=' + data + '&operation=delete';
                });
                         
                   
            });
        });
    
 

        $("#button-save").click(function () {
            
            $('#Save').modal('show'); 
            $('#confirm-save').click(function () {
                $("#form-Permission").submit();
            });
        });
    });
</script>
